package top.broncho.lottery.ui.history

import android.app.Application
import org.jetbrains.anko.info
import top.broncho.lottery.api.LotteryApi
import top.broncho.lottery.data.IRepositoryManager
import top.broncho.lottery.data.obtainRetrofitService
import top.broncho.lottery.data.paging.getListing
import top.broncho.lottery.ui.base.BaseViewModule
import javax.inject.Inject

class HistoryViewModule @Inject constructor(
    private val manager: IRepositoryManager,
    app: Application
) : BaseViewModule(app) {

    val api by lazy { manager.obtainRetrofitService<LotteryApi>() }

    private val listing by lazy { api.getListing() }

    val historyList = listing.pagedList

    val loadingState = listing.loadingState

    fun refresh() {
        info { "onRefresh..." }
        listing.refresh.invoke()
    }

    fun retry() {
        listing.retry.invoke()
    }
}